<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>写芯片</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../js/layui/css/layui.css" media="all">
</head>
<body>
<div style="width:80%;height:570px;margin:15px auto;overflow:auto;" id="aaa">
    <form class="layui-form" action="" id="update_staff">
        <input type="hidden" class="input-text" id="staffId" name="staffId">
        <input type="hidden" class="input-text" id="kk" name="kk">
        <input type="hidden" class="input-text" id="id" name="id">
        <div class="layui-form-item">
            <label class="layui-form-label">卡号</label>
            <div class="layui-input-inline" >
                <input type="text" id="cardNo" name="cardNo" autocomplete="off" class="layui-input" />
            </div>
            <div class="layui-input-inline" style="width: 300px;line-height: 38px;">
                <span style="color: red;">请将工卡放入卡座，如未识别工卡，请重新放入</span>
            </div>
            <!--<div class="layui-form-mid layui-word-aux">辅助文字</div>-->
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">员工编号</label>
            <div class="layui-input-block">
                <input type="text" name="bh" required lay-verify="required" placeholder="请输入会员编号" autocomplete="off" readonly class="layui-input">
            </div>
            <!--<div class="layui-form-mid layui-word-aux">辅助文字</div>-->
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">员工姓名</label>
            <div class="layui-input-block">
                <input type="text" name="name" required  lay-verify="required" placeholder="请输入姓名" autocomplete="off" readonly class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block" id="xinbie">
                <input type="radio" disabled name="sex" value="1" id="nan" title="男" checked=""><div id="y" class="layui-unselect layui-form-radio layui-form-radioed" disabled><i class="layui-anim layui-icon"></i>男</div>
                <input type="radio" disabled name="sex" value="0" id="nv" title="女"><div id="x" class="layui-unselect layui-form-radio" disabled><i class="layui-anim layui-icon"></i>女</div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系方式</label>
            <div class="layui-input-block">
                <input type="text" name="phone" placeholder="请输入联系方式" autocomplete="off" readonly class="layui-input">
            </div>
            <!--<div class="layui-form-mid layui-word-aux">辅助文字</div>-->
        </div>

        <!--<div class="layui-form-item">
            <label class="layui-form-label">证件号码</label>
            <div class="layui-input-block">
                <input type="text" name="sfz" placeholder="请输入证件号码" autocomplete="off" readonly class="layui-input">
            </div>
            &lt;!&ndash;<div class="layui-form-mid layui-word-aux">辅助文字</div>&ndash;&gt;
        </div>-->
        <div class="layui-form-item">
            <label class="layui-form-label">员工头像</label>
            <div class="layui-input-block" style="display: inline;margin-left: 30px;">
                <img class="layui-upload-img" name="picture" id="picture" style="width: 200px;height: 150px">
                <p id="demoText"></p>
            </div>
            <input type="hidden" class="input-text" id="logo" name="logo">
        </div>

        <div class="layui-form-item" style="margin-top: 20px">
            <div class="layui-input-block">
                <button class="layui-btn" id="sfaffKk" lay-submit lay-filter="sfaffKk">会员开卡</button>
            </div>
        </div>
    </form>
</div>
<script src="../../js/layui/layui.js"></script>
<script src="../../js/layui/layui.all.js"></script>
<script src="../../js/config.js"></script>
<script src="../../js/token.js"></script>
<script src="./js/smartReader.js"></script>
<script src="./js/lock.js"></script>
<script src="./js/jquery.min.js"></script>
<script src="./js/card1.js"></script>

<script>

    window.onload = function(){
        var form = layui.form;
        var $ = layui.jquery;
        $("#cardNo").focus() ;
        $.ajax({
            url:HOST+"staff/getUUid",
            beforeSend: function(request) {
                request.setRequestHeader("token", layui.data('local_store').token);
            },
            success:function(res) {
                $("#kk").val(res.data.kk);
            }
        })
        $("input[name='id']").val(GetQueryString("id"));
        $("input[name='name']").val(GetQueryString("name"));
        $("input[name='bh']").val(GetQueryString("bh"));
        var phone = decodeURIComponent(GetQueryString("phone"));
        if (phone=="null" || phone==null || phone=="undefined" || phone == "") {
            $("input[name='phone']").val("");
        }else {
            $("input[name='phone']").val(phone);
        }
        $("input[name='logo']").val(GetQueryString("picture"));
        $("input[name='rztime']").val(GetQueryString("rztime"));
        $("input[name='dqtime']").val(GetQueryString("dqtime"));
        var guoji = decodeURIComponent(GetQueryString("guoji"));
        if (guoji=="null" || guoji==null || guoji=="undefined") {
            $("input[name='guoji']").val("");
        }else {
            $("input[name='guoji']").val(guoji);
        }
        $("input[name='qiye']").val(GetQueryString("qyName"));
        $("#message").val(decodeURIComponent(GetQueryString("message")));
        $('#picture').attr('src', HOST+"upload/"+GetQueryString("picture"));

        var x = GetQueryString("sex");
        if(x==1){
            $("#nan").prop("checked",true);
            form.render()
        }else{
            $("#nv").prop("checked",true);
            form.render()
        }
    }

    layui.use(['form' , 'jquery' , 'upload'], function(){
        var form = layui.form;
        var $ = layui.jquery;
        var upload = layui.upload;

        //修改操作
        form.on('submit(sfaffKk)',function(data){
            var cardNo = $("input[name='cardNo']").val();
            if(cardNo==null || cardNo==""){
                layer.msg('请读取芯片');
            }else{
                layer.confirm("请确认补卡!" , function(){
                    $.ajax({
                        url:HOST+"staff/staffBangka?id="+GetQueryString("id")+"&cardNo="+cardNo ,
                        beforeSend: function(request) {
                            request.setRequestHeader("token", layui.data('local_store').token);
                        },
                        async:false,
                        success:function(res){
                            if (res.code == 200) {
                                layer.msg("补卡成功");
                                setTimeout(function(){
                                    layer.closeAll() ;
                                    parent.location.reload()
                                } , 300)
                            }else {
                                layer.msg(res.msg);
                            }
                        }
                    })
                })
            }
            return false;
        });

        //logo上传
        var uploadInst = upload.render({
            elem: '#test'
            , url: HOST+'upload' //改成您自己的上传接口
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#picture').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //判断上传是否成功
                if (res.code == 0) {
                    $("#logo").val(res.data);
                    return layer.msg('上传成功！');
                }else{
                    return layer.msg('上传失败！');
                }
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
    });
</script>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        var endDate= laydate.render({
            elem: '#end_time',//选择器结束时间
            type: 'datetime',
            min:"1970-1-1",//设置min默认最小值
            done: function(value,date){
                startDate.config.max={
                    year:date.year,
                    month:date.month-1,//关键
                    date: date.date,
                    hours: 0,
                    minutes: 0,
                    seconds : 0
                }
            }
        });

        //日期范围
        var startDate=laydate.render({
            elem: '#start_time',
            type: 'datetime',
            max:"2099-12-31",//设置一个默认最大值
            done: function(value, date){
                endDate.config.min ={
                    year:date.year,
                    month:date.month-1, //关键
                    date: date.date,
                    hours: 0,
                    minutes: 0,
                    seconds : 0
                };
            }
        });
    });
</script>
</body>
</html>